<?php
/*
 * 1626cms 企業用戶相關
 * ============================================================================
 * 版權所有: 1626網絡，并保留所有權利。
 * 網站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 這不是一個自由軟件！您只能在不用于商業目的的前提下對程序代碼進行修改和
 * 使用；不允許對程序代碼以任何形式任何目的的再發布。
 * ============================================================================
 */
define ( 'IN_QISHI', true );
require_once ('../data/config.php');
require_once ('./include/admin_common.inc.php');
require_once (ADMIN_ROOT_PATH . 'include/admin_member_company_fun.php');
! empty ( $_POST ['perpage'] ) ? (setcookie ( 'perpage', intval ( $_POST ['perpage'] ) )) . ($perpage = intval ( $_POST ['perpage'] )) : ($perpage = ! empty ( $_COOKIE ['perpage'] ) ? $_COOKIE ['perpage'] : '10');
$act = ! empty ( $_GET ['act'] ) ? trim ( $_GET ['act'] ) : 'jobs';
//職位列表*****************************************
if ($act == 'jobs') {
	require_once (ADMIN_ROOT_PATH . 'include/page.class.php');
	! empty ( $_GET ['audit'] ) . (trim ( $_GET ['audit'] ) + 0 != 0) ? $wheresqlarr ['audit'] = trim ( $_GET ['audit'] ) : '';
	! empty ( $_GET ['emergency'] ) . (trim ( $_GET ['emergency'] ) + 0 != 0) ? $wheresqlarr ['emergency'] = trim ( $_GET ['emergency'] ) : '';
	//按月查看
	if($_GET['dateline'])
	{
		$dateline= time() - 30 * 24 * 3600;
		$joinsql = " addtime > $dateline ";
	}
	if (is_array ( $wheresqlarr )) {
		$where_set = ' WHERE';
		foreach ( $wheresqlarr as $key => $value ) {
			$wheresql .= $where_set . $comma . '`' . $key . '`' . '=\'' . $value . '\'';
			$comma = ' AND ';
			$where_set = '';
		}
	}
	$key = trim ( $_POST ['key'] );
	! empty ( $key ) ? ($wheresql = " WHERE jobs_name_cn like '%{$key}%' or jobs_name_en like '%{$key}%'") : '';

	//增加時間信息內容
	if ($joinsql){
		if($wheresql){
		 $wheresql = $wheresql .' AND ' . $joinsql;
		}else
		{
			$wheresql = ' WHERE ' . $joinsql;
		}
	}

	$total_sql = "SELECT COUNT(*) AS num FROM " . table ( 'jobs' ) . $wheresql;
	$total_val = get_total ( $total_sql );
	$page = new page ( array ('total' => $total_val, 'perpage' => $perpage ) );
	$currenpage = $page->nowindex;
	$offset = ($currenpage - 1) * $perpage;
	$list = get_jobs ( $offset, $perpage, $wheresql );
	$smarty->assign ( 'pageheader', "管理中心 - 招聘信息" );
	$smarty->assign ( 'audit', $_GET ['audit'] ); //審核狀態
	$smarty->assign ( 'emergency', $_GET ['emergency'] ); //屬性
	$smarty->assign ( 'key', $key ); //關鍵字POST
	$smarty->assign ( 'perpage', $perpage ); //每頁顯示數量POST
	$smarty->assign ( 'list', $list ); //列表
	if ($total_val > $perpage) {
		$smarty->assign ( 'page', $page->show ( 3 ) ); //分頁符
	}
	$smarty->display ( 'admin_member_company_jobs.htm' );
}
//職位刪除，更改審核狀態
if ($act == 'jobs_perform') {
	$yid = trim ( $_REQUEST ['y_id'] ) ? $_REQUEST ['y_id'] : showmsg ( "你沒有選擇職位！", 1 );
	$link [0] ['text'] = "返回上一頁";
	$link [0] ['href'] = $_SERVER ['HTTP_REFERER'];
	$delete = trim ( $_REQUEST ['delete'] );
	echo ("<script>window.parent.leftFrame.location.href='admin_index.php?act=left';</script>");
	$delete ? (! del_jobs ( $yid ) ? showmsg ( "刪除失敗！", 0 ) : showmsg ( "刪除成功！", 2, $link )) : '';
	trim ( $_REQUEST ['perform1'] ) ? (! edit_jobs_audit ( $yid, 1 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_REQUEST ['perform2'] ) ? (! edit_jobs_audit ( $yid, 2 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_REQUEST ['perform3'] ) ? (! edit_jobs_audit ( $yid, 3 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_REQUEST ['emergency1'] ) ? (! edit_jobs_emergency ( $yid, 1 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_REQUEST ['emergency2'] ) ? (! edit_jobs_emergency ( $yid, 2 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
}
//修改職位
if ($act == 'edit_jobs') {

	require_once (ADMIN_ROOT_PATH . 'include/admin_fun_category.php');
	$yid = trim ( $_REQUEST ['id'] ) ? $_REQUEST ['id'] : showmsg ( "你沒有選擇職位！", 1 );
	$smarty->assign ( 'pageheader', "管理中心 - 招聘信息 - 修改招聘信息" );
	$jobs = get_jobs_one ( $yid );
	$jobs ['jobs_rest_day'] = explode ( '|', $jobs ['jobs_rest_day'] );
	$jobs ['jobs_experience'] = explode ( '|', $jobs ['jobs_experience'] );
	$company_profile = get_company_profile_one_byuid( $jobs['uid'] );
	$smarty->assign ( 'url', $_SERVER ["HTTP_REFERER"] );
	$smarty->assign ( 'company_profile', $company_profile );
	$smarty->assign ( 'jobs', $jobs );
	$smarty->assign ( 'education', get_jobs_education () );
	$smarty->assign ( 'attachment', get_jobs_attachment (trim ( $_GET ['id'] ) ));
	$smarty->assign ( 'trade', get_jobs_trade () );
	$smarty->assign ( 'jobs_other_wage', get_jobs_other_wage ( trim ( $_GET ['id'] ) ) );
	$smarty->assign ( 'nature', get_jobs_nature () );
	$smarty->assign ( 'shiftwork', get_jobs_shiftwork ( trim ( $_GET ['id'] ) ) );
	$smarty->display ( 'admin_member_company_jobs_edit.htm' );
}
//保存修改的職位
if ($act == 'editjobs_save') {
	//計算積分
	$id = trim ( $_POST ['id'] );
	if (intval ( $id ) != $id)
	showmsg ( '參數錯誤！', 0 );


	$tablename = table ( 'jobs' );
	$tablename_attachment = table ( 'jobs_attachment' );
	$tablename_shiftwork = table ( 'jobs_shiftwork' );
	$tablename_skills = table ( 'jobs_skills' );
	$setsqlarr = array ();
	$setsqlarr_contents = array ();
	$setsqlarr_shiftwork = array ();

	/*
	 $setsqlarr['company_name_en']=trim($_POST['company_name_en']);
	 $setsqlarr['company_name_cn']=trim($_POST['company_name_cn']);
	 if('' == $setsqlarr['company_name_cn'] && '' == $setsqlarr['company_name_en'])
	 {
	 showmsg('您沒有輸入公司名稱！',1);
	 }
	 $setsqlarr['trade']=trim($_POST['trade'])?trim($_POST['trade']):showmsg('您沒有輸入所屬行業！',1);
	 $setsqlarr['trade_option']=trim($_POST['trade_option']);
	 $setsqlarr['stuff_number']=trim($_POST['stuff_number'])?trim($_POST['stuff_number']):showmsg('您沒有輸入現有僱員人數！',1);
	 $setsqlarr['school_number']=trim($_POST['school_number']);
	 $setsqlarr['reg_number_pre']=trim($_POST['reg_number_pre']);
	 $setsqlarr['reg_number_suf']=trim($_POST['reg_number_suf']);

	 $setsqlarr['contact_gender_en']=trim($_POST['contact_gender_en'])?trim($_POST['contact_gender_en']):1;
	 $setsqlarr['contact_gender_cn']=trim($_POST['contact_gender_cn'])?trim($_POST['contact_gender_cn']):1;
	 $setsqlarr['contact_en']=trim($_POST['contact_en']);
	 $setsqlarr['contact_cn']=trim($_POST['contact_cn']);
	 if('' == $setsqlarr['contact_cn'] && '' == $setsqlarr['contact_en'])
	 {
	 showmsg('您沒有輸入聯絡人姓名！',1);
	 }
	 $setsqlarr['telephone']=trim($_POST['telephone']);
	 $setsqlarr['telephone_inline']=trim($_POST['telephone_inline']);
	 $setsqlarr['telephone_option']=trim($_POST['telephone_option'])?trim($_POST['telephone_option']):1;
	 if('' == $setsqlarr['telephone'] && '' == $setsqlarr['telephone_inline'])
	 {
	 showmsg('您沒有輸入電話號碼！',1);
	 }
	 $setsqlarr['email']=trim($_POST['email'])?trim($_POST['email']):showmsg('您沒有輸入聯系郵箱！',1);
	 $setsqlarr['address_1_en']=trim($_POST['address_1_en']);
	 $setsqlarr['address_2_en']=trim($_POST['address_2_en']);
	 $setsqlarr['address_3_en']=trim($_POST['address_3_en']);
	 $setsqlarr['address_1_cn']=trim($_POST['address_1_cn']);
	 $setsqlarr['address_2_cn']=trim($_POST['address_2_cn']);
	 $setsqlarr['address_3_cn']=trim($_POST['address_3_cn']);
	 if('' == $setsqlarr['address_1_en'] && '' == $setsqlarr['address_2_en'] && '' == $setsqlarr['address_3_en']
	 &&'' == $setsqlarr['address_1_cn'] && '' == $setsqlarr['address_2_cn'] && '' == $setsqlarr['address_3_cn'])
	 {
	 showmsg('您沒有輸入公司地址！',1);
	 }*/
	//======================================================================//
	$setsqlarr ['uid'] = trim ( $_SESSION ['uid'] );
	$setsqlarr ['jobs_name_cn'] = trim ( $_POST ['jobs_name_cn'] );
	$setsqlarr ['jobs_name_en'] = trim ( $_POST ['jobs_name_en'] );
	if ('' == $setsqlarr ['jobs_name_en'] && '' == $setsqlarr ['jobs_name_cn']) {
		showmsg ( '您沒有輸入職位空缺名稱！', 1 );
	}
	$setsqlarr ['jobs_description_cn'] = trim ( $_POST ['jobs_description_cn'] );
	$setsqlarr ['jobs_description_en'] = trim ( $_POST ['jobs_description_en'] );
	if ('' == $setsqlarr ['jobs_description_cn'] && '' == $setsqlarr ['jobs_description_en']) {
		showmsg ( '您沒有輸入職位描述！', 1 );
	}
	$setsqlarr ['jobs_request'] = trim ( $_POST ['jobs_request'] ) ? trim ( $_POST ['jobs_request'] ) : showmsg ( '您沒有選擇申請方法！', 1 );
	$setsqlarr ['jobs_amount'] = trim ( $_POST ['jobs_amount'] ) ? trim ( $_POST ['jobs_amount'] ) : showmsg ( '您沒有輸入空缺數目！', 1 );
	$setsqlarr ['jobs_employ_type'] = trim ( $_POST ['jobs_employ_type'] ) ? trim ( $_POST ['jobs_employ_type'] ) : showmsg ( '您沒有選擇聘用形式！', 1 );
	$setsqlarr ['jobs_nature'] = intval ( $_POST ['jobs_nature'] ) ? intval ( $_POST ['jobs_nature'] ) : showmsg ( '您沒有選擇聘用形式！', 1 );
	$setsqlarr ['jobs_week_from'] = trim ( $_POST ['jobs_week_from'] ) ? trim ( $_POST ['jobs_week_from'] ) : showmsg ( '您沒有輸入每週工作天數！', 1 );
	$setsqlarr ['jobs_week_to'] = trim ( $_POST ['jobs_week_to'] ) ? trim ( $_POST ['jobs_week_to'] ) : showmsg ( '您沒有輸入每週工作天數！', 1 );
	if (2 == $_POST ['jobs_employ_type'] || 3 == $_POST ['jobs_employ_type']) {
		if (1 == $_POST ['jobs_hire_period']) {
			if ('' == $_POST ['jobs_hire_period_content']) {
				showmsg ( '您沒有輸入臨時工或暑期工工作期！', 1 );
			}
		}
		if (2 == $_POST ['jobs_hire_period']) {
			if ('' == $_POST ['jobs_hire_periodfrom'] || '' == $_POST ['jobs_hire_periodto']) {
				showmsg ( '您沒有輸入臨時工工作期！', 1 );
			}
		}
		$setsqlarr ['jobs_hire_period'] = $_POST ['jobs_hire_period'];
		$setsqlarr ['jobs_hire_periodfrom'] = $_POST ['jobs_hire_periodfrom'];
		$setsqlarr ['jobs_hire_periodto'] = $_POST ['jobs_hire_periodto'];
		$setsqlarr ['jobs_hire_period_content'] = $_POST ['jobs_hire_period_content'];
	}
	$setsqlarr ['jobs_need_experience'] = intval ( $_POST ['jobs_need_experience'] ) ? intval ( $_POST ['jobs_need_experience'] ) : 2;
	if (1 == $setsqlarr ['jobs_need_experience']) {
		$setsqlarr ['jobs_year_from'] = $_POST ['year_from'];
		$setsqlarr ['jobs_month_from'] = $_POST ['month_from'];
	}
	else
	{
		$setsqlarr ['jobs_year_from'] = 0;
		$setsqlarr ['jobs_month_from'] = 0;
	}
	$j_exp = '';
	if($_POST['jobs_experience'])
	{
		foreach($_POST['jobs_experience'] as $je)
		{
			if($j_exp == '')
			{
				$j_exp = $je;
			}
			else
			{
				$j_exp = $j_exp. '|'. $je;
			}
		}
	}
	$setsqlarr ['jobs_experience'] = $j_exp;
	$setsqlarr ['jobs_speak_canfirst'] = $_POST ['jobs_speak_canfirst'];
	$setsqlarr ['jobs_speak_cnfirst'] = $_POST ['jobs_speak_cnfirst'];
	$setsqlarr ['jobs_speak_enfirst'] = $_POST ['jobs_speak_enfirst'];
	$setsqlarr ['jobs_hour_from'] = trim ( $_POST ['jobs_hour_from'] ) ? trim ( $_POST ['jobs_hour_from'] ) : showmsg ( '您沒有輸入每天工作時數！', 1 );
	$setsqlarr ['jobs_hour_to'] = trim ( $_POST ['jobs_hour_to'] ) ? trim ( $_POST ['jobs_hour_to'] ) : showmsg ( '您沒有輸入每天工作時數！', 1 );
	$setsqlarr ['jobs_shift'] = trim ( $_POST ['jobs_shift'] ) ? trim ( $_POST ['jobs_shift'] ) : showmsg ( '您沒有選擇需輪班！', 1 );
	if (count ( $_POST ['jobs_rest_day'] ) > 0) {
		$setsqlarr ['jobs_rest_day'] = implode ( '|', $_POST ['jobs_rest_day'] );
	} else {
		showmsg ( '您沒有選擇休息日！', 1 );
	}
	$setsqlarr ['jobs_address'] = trim ( $_POST ['jobs_address'] ) ? trim ( $_POST ['jobs_address'] ) : showmsg ( '您沒有輸入工作地點！', 1 );
	$setsqlarr ['jobs_wage_from'] = trim ( $_POST ['jobs_wage_from'] ) ? trim ( $_POST ['jobs_wage_from'] ) : showmsg ( '您沒有輸入基本薪金！', 1 );
	$setsqlarr ['jobs_wage_to'] = trim ( $_POST ['jobs_wage_to'] ) ? trim ( $_POST ['jobs_wage_to'] ) : showmsg ( '您沒有輸入基本薪金！', 1 );
	$setsqlarr ['jobs_wage_per'] = trim ( $_POST ['jobs_wage_per'] ) ? trim ( $_POST ['jobs_wage_per'] ) : 'month';
	$setsqlarr ['jobs_wage_double'] = trim ( $_POST ['jobs_wage_double'] ) ? trim ( $_POST ['jobs_wage_double'] ) : 0;
	$setsqlarr ['jobs_hour_other'] = trim ( $_POST ['jobs_hour_other'] ) ? trim ( $_POST ['jobs_hour_other'] ) : '';

	$setsqlarr ['jobs_wage_memo'] = trim ( $_POST ['jobs_wage_memo'] ) ? trim ( $_POST ['jobs_wage_memo'] ) : '';
	$setsqlarr ['jobs_education'] = trim ( $_POST ['jobs_education'] ) ? trim ( $_POST ['jobs_education'] ) : '';
	$setsqlarr ['jobs_education_option'] = trim ( $_POST ['jobs_education_option'] ) ? trim ( $_POST ['jobs_education_option'] ) : '';
	$setsqlarr ['jobs_speak_can'] = trim ( $_POST ['jobs_speak_can'] ) ? trim ( $_POST ['jobs_speak_can'] ) : '';
	$setsqlarr ['jobs_speak_en'] = trim ( $_POST ['jobs_speak_en'] ) ? trim ( $_POST ['jobs_speak_en'] ) : '';
	$setsqlarr ['jobs_speak_cn'] = trim ( $_POST ['jobs_speak_cn'] ) ? trim ( $_POST ['jobs_speak_cn'] ) : '';

	$setsqlarr ['jobs_read_cn'] = trim ( $_POST ['jobs_read_cn'] ) ? trim ( $_POST ['jobs_read_cn'] ) : '';
	$setsqlarr ['jobs_read_en'] = trim ( $_POST ['jobs_read_en'] ) ? trim ( $_POST ['jobs_read_en'] ) : '';
	$setsqlarr ['jobs_other_cn'] = trim ( $_POST ['jobs_other_cn'] ) ? trim ( $_POST ['jobs_other_cn'] ) : '';
	$setsqlarr ['jobs_other_en'] = trim ( $_POST ['jobs_other_en'] ) ? trim ( $_POST ['jobs_other_en'] ) : '';
	$setsqlarr ['jobs_other_level'] = trim ( $_POST ['jobs_other_level'] ) ? trim ( $_POST ['jobs_other_level'] ) : '';
	$setsqlarr ['jobs_require_cn'] = trim ( $_POST ['jobs_require_cn'] ) ? trim ( $_POST ['jobs_require_cn'] ) : '';
	$setsqlarr ['jobs_require_en'] = trim ( $_POST ['jobs_require_en'] ) ? trim ( $_POST ['jobs_require_en'] ) : '';

	$setsqlarr ['jobs_boss'] = trim ( $_POST ['jobs_boss'] ) ? trim ( $_POST ['jobs_boss'] ) : showmsg ( '您沒有輸入公司代表/僱主姓名！', 1 );
	$setsqlarr ['display'] = trim ( $_POST ['display'] ); //屏蔽激活
	$setsqlarr ['audit'] = trim ( $_POST ['audit'] ); //審核狀態

	if ($company_audit ['audit'] == 1) //根據認證狀態設置是否需要審核
	{
		$_CFG ['audit_verify'] == 1 ? $setsqlarr ['audit'] = 2 : $setsqlarr ['audit'] = 1;
	} else {
		$_CFG ['audit_unexamined'] == 1 ? $setsqlarr ['audit'] = 2 : $setsqlarr ['audit'] = 1;
	}
	//添加職位信息
	$wheresql = " id='" . $id. "'";
	if (! updatetable ( $tablename, $setsqlarr, $wheresql ))
	showmsg ( "保存失敗！", 0 );

	if (1 == $setsqlarr ['jobs_shift']) {
		foreach ( $_POST ['jobs_hour_opt'] as $value ) {
			$jobs_hour_opt [] = trim ( $value ) ? trim ( $value ) : '';
		}
		foreach ( $_POST ['jobs_hour_opt2'] as $value2 ) {
			$jobs_hour_opt2 [] = trim ( $value2 ) ? trim ( $value2 ) : '';
		}
		foreach ( $_POST ['jobs_mm_opt'] as $value3 ) {
			$jobs_mm_opt [] = trim ( $value3 ) ? trim ( $value3 ) : '';
		}
		foreach ( $_POST ['jobs_mm_opt2'] as $value4 ) {
			$jobs_mm_opt2 [] = trim ( $value4 ) ? trim ( $value4 ) : '';
		}
		foreach ( $_POST ['jobs_ss_opt'] as $value5 ) {
			$jobs_ss_opt [] = trim ( $value5 ) ? trim ( $value5 ) : '';
		}
		foreach ( $_POST ['jobs_ss_opt2'] as $value6 ) {
			$jobs_ss_opt2 [] = trim ( $value6 ) ? trim ( $value6 ) : '';
		}
		if (isset ( $jobs_hour_opt ) && count ( $jobs_hour_opt ) > 0) {
			del_jobs_shiftwork ( $id );

			foreach ( $jobs_hour_opt as $k => $v ) {
				$setsqlarr_shiftwork ['jobs_hour_opt'] = $jobs_hour_opt [$k];
				$setsqlarr_shiftwork ['jobs_hour_opt2'] = $jobs_hour_opt2 [$k];
				$setsqlarr_shiftwork ['jobs_mm_opt'] = $jobs_mm_opt [$k];
				$setsqlarr_shiftwork ['jobs_mm_opt2'] = $jobs_mm_opt2 [$k];
				$setsqlarr_shiftwork ['jobs_ss_opt'] = $jobs_ss_opt [$k];
				$setsqlarr_shiftwork ['jobs_ss_opt2'] = $jobs_ss_opt2 [$k];
				$setsqlarr_shiftwork ['job_id'] = $id;
				if ('' != trim ( $jobs_hour_opt [$k] ) || '' != trim ( $jobs_hour_opt2 [$k] ) || '' != trim ( $jobs_mm_opt [$k] ) || '' != trim ( $jobs_mm_opt2 [$k] ) || '' != trim ( $jobs_ss_opt [$k] ) || '' != trim ( $jobs_ss_opt2 [$k] )) {
					! inserttable ( table ( 'jobs_shiftwork' ), $setsqlarr_shiftwork ) ? showmsg ( "添加失敗！", 0 ) : '';
				}
			}
		}
	}

	foreach ( $_POST ['jobs_other_wage'] as $i ) {
		$jobs_other_wage [] = trim ( $i ) ? trim ( $i ) : '';
	}
	foreach ( $_POST ['jobs_other_wageopt'] as $i2 ) {
		$jobs_other_wageopt [] = trim ( $i2 ) ? trim ( $i2 ) : '';
	}
	foreach ( $_POST ['jobs_other_wageday'] as $i3 ) {
		$jobs_other_wageday [] = trim ( $i3 ) ? trim ( $i3 ) : '';
	}
	if (isset ( $jobs_other_wage ) && count ( $jobs_other_wage ) > 0) {
		del_jobs_welfare ( $id );
		foreach ( $jobs_other_wage as $kj => $vj ) {
			$setsqlarr_walfare ['jobs_other_wage'] = $jobs_other_wage [$kj];
			$setsqlarr_walfare ['jobs_other_wageopt'] = $jobs_other_wageopt [$kj];
			$setsqlarr_walfare ['jobs_other_wageday'] = $jobs_other_wageday [$kj];
			$setsqlarr_walfare ['job_id'] = $id;
			if ('' != trim ( $jobs_other_wageday [$kj] ) || '' != trim ( $jobs_other_wageopt [$kj] ) || '' != trim ( $jobs_other_wage [$kj] )) {
				! inserttable ( table ( 'jobs_welfare' ), $setsqlarr_walfare ) ? showmsg ( "添加失敗！", 0 ) : '';
			}
		}
	}

	$wheresql = " id='" . $id . "' ";
	if (! updatetable ( $tablename, $setsqlarr, $wheresql ))
	showmsg ( "保存失敗！", 0 );
	$wheresql = " pid='" . $id . "' ";
	unset ( $setsqlarr_contents, $setsqlarr_shiftwork, $setsqlarr );
	$link [0] ['text'] = "返回職位列表";
	$link [0] ['href'] = $_POST ['url'];
	showmsg ( "修改成功！", 2, $link );
}
//***************************************企業管理****************************************
//企業列表
if ($act == 'company_list') {
	require_once (ADMIN_ROOT_PATH . 'include/page.class.php');
	is_numeric ( $_GET ['audit'] ) ? $wheresqlarr ['audit'] = $_GET ['audit'] : '';
	is_numeric ( $_GET ['recommend'] ) ? $wheresqlarr ['recommend'] = $_GET ['recommend'] : '';
	//按月查看
	if($_GET['dateline'])
	{
		$dateline= time() - 30 * 24 * 3600;
		$joinsql = " addtime > $dateline ";
	}
	if (is_array ( $wheresqlarr )) {
		$where_set = ' WHERE';
		foreach ( $wheresqlarr as $key => $value ) {
			$wheresql .= $where_set . $comma . '`' . $key . '`' . '=\'' . $value . '\'';
			$comma = ' AND ';
			$where_set = '';
		}
	}
	$key = $_POST ['key'] ? trim ( $_POST ['key'] ) : '';
	if ($key)
	$wheresql = " WHERE company_name_cn like '%{$key}%' OR company_name_en like '%{$key}%'";
	//增加按月查詢條件
	if($joinsql){
		if($wheresql){
			$wheresql = $wheresql .' AND ' . $joinsql;
		}else
		{
			$wheresql = ' WHERE ' . $joinsql;
		}
	}
	$total_sql = "SELECT COUNT(*) AS num FROM " . table ( 'company_profile' ) . $wheresql;
	$total_val = get_total ( $total_sql );
	$page = new page ( array ('total' => $total_val, 'perpage' => $perpage ) );
	$currenpage = $page->nowindex;
	$offset = ($currenpage - 1) * $perpage;
	$list = get_company_profile ( $offset, $perpage, $wheresql );
	$smarty->assign ( 'pageheader', "管理中心 - 企業列表" );
	$smarty->assign ( 'audit', $_GET ['audit'] ); //認證狀態
	$smarty->assign ( 'recommend', $_GET ['recommend'] ); //是否推薦
	$smarty->assign ( 'key', $key ); //關鍵字POST
	$smarty->assign ( 'perpage', $perpage ); //每頁顯示數量POST
	$smarty->assign ( 'list', $list ); //列表
	$smarty->assign ( 'certificate_dir', $certificate_dir ); //營業執照路徑
	if ($total_val > $perpage) {
		$smarty->assign ( 'page', $page->show ( 3 ) ); //分頁符
	}
	$smarty->display ( 'admin_member_company_list.htm' );
}
//刪除企業，更改企業認證狀態，推薦狀態
if ($act == 'company_perform') {
	$u_id = trim ( $_POST ['y_id'] ) ? $_POST ['y_id'] : showmsg ( "你沒有選擇企業！", 1 );
	if ($_POST ['delete']) {
		$_POST ['delete_company'] == 'yes' ? (! del_company ( $u_id ) ? showmsg ( "刪除企業資料失敗！", 0 ) . (exit ()) : "") : '';
		$_POST ['delete_jobs'] == 'yes' ? (! del_company_alljobs ( $u_id ) ? showmsg ( "刪除職位失敗！", 0 ) . (exit ()) : "") : '';
		showmsg ( "刪除成功！", 2 );
	}
	echo ("<script>window.parent.leftFrame.location.href='admin_index.php?act=left';</script>");
	$link [0] ['text'] = "返回上一頁";
	$link [0] ['href'] = $_SERVER ['HTTP_REFERER'];
	trim ( $_POST ['audit1'] ) ? (! edit_company_audit ( $u_id, 1 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_POST ['audit2'] ) ? (! edit_company_audit ( $u_id, 2 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_POST ['audit3'] ) ? (! edit_company_audit ( $u_id, 3 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_POST ['recommend1'] ) ? (! edit_company_recommend ( $u_id, 1 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
	trim ( $_POST ['recommend0'] ) ? (! edit_company_recommend ( $u_id, 0 ) ? showmsg ( "設置失敗！", 0 ) : showmsg ( "設置成功！", 2, $link )) : '';
}
//修改企業資料
if ($act == 'edit_company_profile') {
	require_once (ADMIN_ROOT_PATH . 'include/admin_fun_category.php');
	$yid = trim ( $_REQUEST ['id'] ) ? $_REQUEST ['id'] : showmsg ( "你沒有選擇企業！", 1 );
	$smarty->assign ( 'pageheader', "管理中心 - 企業列表 - 修改企業信息" );
	$company_profile = get_company_profile_one ( $yid );
	$smarty->assign ( 'url', $_SERVER ["HTTP_REFERER"] );
	$smarty->assign ( 'company_profile', $company_profile );
	$smarty->assign ( 'company_profile_contents', get_company_profile_contents ( $company_profile ['uid'] ) );
	$smarty->assign ( 'nature', get_jobs_corporation () );
	$smarty->assign ( 'trade', get_jobs_trade () );
	$smarty->assign ( 'area', get_jobs_area () );
	$smarty->assign ( 'scale', get_jobs_scale () );
	$smarty->assign ( 'certificate_dir', $certificate_dir ); //營業執照路徑
	$smarty->display ( 'admin_member_company_profile_edit.htm' );
}
//保存企業資料
if ($act == 'company_profile_save') {
	$setsqlarr = array ();
	$contents = array ();

	$companyuid = intval ( $_POST ['companyuid'] );
	$setsqlarr ['audit'] = intval ( $_POST ['audit'] );
	$setsqlarr ['company_name_en'] = trim ( $_POST ['company_name_en'] );
	$setsqlarr ['company_name_cn'] = trim ( $_POST ['company_name_cn'] );
	if ('' == $setsqlarr ['company_name_cn'] && '' == $setsqlarr ['company_name_en']) {
		showmsg ( '您沒有輸入公司名稱！', 1 );
	}
	$setsqlarr ['trade'] = trim ( $_POST ['trade'] ) ? trim ( $_POST ['trade'] ) : showmsg ( '您沒有輸入所屬行業！', 1 );
	$setsqlarr ['trade_option'] = trim ( $_POST ['trade_option'] );
	$setsqlarr ['stuff_number'] = trim ( $_POST ['stuff_number'] ) ? trim ( $_POST ['stuff_number'] ) : showmsg ( '您沒有輸入現有僱員人數！', 1 );
	$setsqlarr ['school_number'] = trim ( $_POST ['school_number'] );
	$setsqlarr ['reg_number_pre'] = trim ( $_POST ['reg_number_pre'] );
	$setsqlarr ['reg_number_suf'] = trim ( $_POST ['reg_number_suf'] );

	$setsqlarr ['contact_gender_en'] = trim ( $_POST ['contact_gender_en'] ) ? trim ( $_POST ['contact_gender_en'] ) : 1;
	$setsqlarr ['contact_gender_cn'] = trim ( $_POST ['contact_gender_cn'] ) ? trim ( $_POST ['contact_gender_cn'] ) : 1;
	$setsqlarr ['contact_en'] = trim ( $_POST ['contact_en'] );
	$setsqlarr ['contact_cn'] = trim ( $_POST ['contact_cn'] );
	if ('' == $setsqlarr ['contact_cn'] && '' == $setsqlarr ['contact_en']) {
		showmsg ( '您沒有輸入聯絡人姓名！', 1 );
	}
	$setsqlarr ['telephone'] = trim ( $_POST ['telephone'] );
	$setsqlarr ['telephone_inline'] = trim ( $_POST ['telephone_inline'] );
	$setsqlarr ['telephone_option'] = trim ( $_POST ['telephone_option'] ) ? trim ( $_POST ['telephone_option'] ) : 1;
	if ('' == $setsqlarr ['telephone'] && '' == $setsqlarr ['telephone_inline']) {
		showmsg ( '您沒有輸入電話號碼！', 1 );
	}
	$setsqlarr ['email'] = trim ( $_POST ['email'] ) ? trim ( $_POST ['email'] ) : showmsg ( '您沒有輸入聯系郵箱！', 1 );
	$setsqlarr ['address_1_en'] = trim ( $_POST ['address_1_en'] );
	$setsqlarr ['address_2_en'] = trim ( $_POST ['address_2_en'] );
	$setsqlarr ['address_3_en'] = trim ( $_POST ['address_3_en'] );
	$setsqlarr ['address_1_cn'] = trim ( $_POST ['address_1_cn'] );
	$setsqlarr ['address_2_cn'] = trim ( $_POST ['address_2_cn'] );
	$setsqlarr ['address_3_cn'] = trim ( $_POST ['address_3_cn'] );
	if ('' == $setsqlarr ['address_1_en'] && '' == $setsqlarr ['address_2_en'] && '' == $setsqlarr ['address_3_en'] && '' == $setsqlarr ['address_1_cn'] && '' == $setsqlarr ['address_2_cn'] && '' == $setsqlarr ['address_3_cn']) {
		showmsg ( '您沒有輸入公司地址！', 1 );
	}
	$setsqlarr ['fax'] = trim ( $_POST ['fax'] );
	$tablename = table ( 'company_profile' );
	$link [0] ['text'] = "返回列表";
	$link [0] ['href'] = $_POST ['url'];
	$wheresql = " uid='" . $companyuid . "' ";

	if (updatetable ( $tablename, $setsqlarr, $wheresql )) {
		unset ( $setsqlarr, $contents );
		showmsg ( "保存成功！", 2, $link );
	} else {
		unset ( $setsqlarr, $contents );
		showmsg ( "保存失敗！", 0 );
	}
}
//會員充值記錄列表*****************************************
if ($act == 'pay_list') {
	require_once (ADMIN_ROOT_PATH . 'include/page.class.php');
	require_once (ADMIN_ROOT_PATH . 'include/admin_payment_fun.php');
	$is_paid = trim ( $_GET ['is_paid'] );
	$payment_name = trim ( $_GET ['payment_name'] );
	$wheresql = " WHERE  id IS NOT NULL ";
	if (is_numeric ( $is_paid ))
	$wheresql .= " AND is_paid='" . $is_paid . "' ";
	if ($payment_name)
	$wheresql .= " AND  payment_name='" . $payment_name . "' ";
	$total_sql = "SELECT COUNT(*) AS num FROM " . table ( 'payment_log' ) . $wheresql;
	$total_val = get_total ( $total_sql );
	$page = new page ( array ('total' => $total_val, 'perpage' => $perpage ) );
	$currenpage = $page->nowindex;
	$offset = ($currenpage - 1) * $perpage;
	$list = get_pay_list ( $offset, $perpage, $wheresql );
	$smarty->assign ( 'pageheader', "管理中心 - 充值記錄" );
	$smarty->assign ( 'is_paid', $is_paid ); //狀態
	$smarty->assign ( 'payment_name', $payment_name ); //付款方式
	$smarty->assign ( 'payment_list', get_payment ( 2 ) ); //付款方式列表
	$smarty->assign ( 'perpage', $perpage ); //每頁顯示數量POST
	$smarty->assign ( 'list', $list ); //列表
	if ($total_val > $perpage) {
		$smarty->assign ( 'page', $page->show ( 3 ) ); //分頁符
	}
	$smarty->display ( 'admin_member_pay_list.htm' );
}
//查看充值記錄
if ($act == 'show_payment') {
	$smarty->assign ( 'pageheader', "管理中心 - 充值記錄 - 查看" );
	$smarty->assign ( 'url', $_SERVER ["HTTP_REFERER"] );
	$smarty->assign ( 'payment', get_pay_one ( $_GET ['id'] ) );
	$smarty->display ( 'admin_member_pay_show.htm' );
}
//保存充值記錄的備注
if ($act == 'pay_notes_save') {
	$link [0] ['text'] = "返回列表";
	$link [0] ['href'] = $_POST ['url'];
	! $db->query ( "UPDATE " . table ( "payment_log" ) . " SET  notes='" . $_POST ['notes'] . "' WHERE id='" . intval ( $_GET ['id'] ) . "'" ) ? showmsg ( '操作失敗', 1 ) : showmsg ( "操作成功！", 2, $link );
}
//設置充值記錄（收款開通）
if ($act == 'pay_set') {
	$smarty->assign ( 'pageheader', "管理中心 - 充值記錄 - 設置" );
	$smarty->assign ( 'url', $_SERVER ["HTTP_REFERER"] );
	$smarty->assign ( 'payment', get_pay_one ( $_GET ['id'] ) );
	$smarty->display ( 'admin_member_pay_set.htm' );
}
//確認收款開通
if ($act == 'pay_set_save') {
	$link [0] ['text'] = "返回列表";
	$link [0] ['href'] = $_POST ['url'];
	if (order_paid ( trim ( $_POST ['oid'] ) )) {
		! $db->query ( "UPDATE " . table ( "payment_log" ) . " SET is_paid='2',payment_time='" . $timestamp . "',notes='" . $_POST ['notes'] . "' WHERE id='" . intval ( $_GET ['id'] ) . "'" ) ? showmsg ( '操作失敗', 1 ) : showmsg ( "操作成功！", 2, $link );
	} else {
		showmsg ( '操作失敗', 1 );
	}
}
//取消會員充值申請
if ($act == 'del_payment') {
	if (del_payment ( $_GET ['id'] )) {
		echo ("<script>window.parent.leftFrame.location.href='admin_index.php?act=left';</script>");
		$link [0] ['text'] = "返回上一頁";
		$link [0] ['href'] = $_SERVER ['HTTP_REFERER'];
		showmsg ( "取消成功！", 2, $link );
	} else {
		showmsg ( "取消失敗！", 1 );
	}
}
//*****************************************企業會員***************************
//企業會員列表
if ($act == 'members_list') {
	require_once (ADMIN_ROOT_PATH . 'include/page.class.php');
	$key = trim ( $_POST ['key'] );
	$wheresql = " WHERE uid IN (SELECT uid FROM " . table ( 'members_type' ) . " WHERE utype='1')";
	if ($key)
	$wheresql .= " AND ( username like '%{$key}%' OR email like '%{$key}%')";
	$wheresql .= " ORDER BY uid desc ";
	$total_sql = "SELECT COUNT(*) AS num FROM " . table ( 'members' ) . $wheresql;
	$total_val = get_total ( $total_sql );
	$page = new page ( array ('total' => $total_val, 'perpage' => $perpage ) );
	$currenpage = $page->nowindex;
	$offset = ($currenpage - 1) * $perpage;
	$list = get_member_list ( $offset, $perpage, $wheresql );
	$smarty->assign ( 'pageheader', "管理中心 - 企業會員列表" );
	$smarty->assign ( 'key', $key ); //狀態
	$smarty->assign ( 'perpage', $perpage ); //每頁顯示數量POST
	$smarty->assign ( 'list', $list ); //列表
	if ($total_val > $perpage) {
		$smarty->assign ( 'page', $page->show ( 3 ) ); //分頁符
	}
	$smarty->display ( 'admin_member_company_user_list.htm' );
}
//刪除會員
if ($act == 'delete_user') {
	$u_id = trim ( $_POST ['y_id'] ) ? $_POST ['y_id'] : showmsg ( "你沒有選擇會員！", 1 );
	if ($_POST ['delete']) {
		trim ( $_POST ['delete_user'] ) === 'yes' ? (! delete_company_user ( $u_id ) ? showmsg ( "刪除會員失敗！", 0 ) . (exit ()) : "") : '';
		trim ( $_POST ['delete_company'] ) === 'yes' ? (! del_company ( $u_id ) ? showmsg ( "刪除企業資料失敗！", 0 ) . (exit ()) : "") : '';
		trim ( $_POST ['delete_jobs'] ) === 'yes' ? (! del_company_alljobs ( $u_id ) ? showmsg ( "刪除職位失敗！", 0 ) . (exit ()) : "") : '';
		showmsg ( "刪除成功！", 2 );
	}
}
//添加會員
if ($act == 'members_add') {
	$smarty->assign ( 'pageheader', "管理中心 - 企業會員 - 添加企業會員" );
	$smarty->display ( 'admin_member_company_user_add.htm' );
}
//保存添加會員
if ($act == 'members_add_save') {
	require_once (ADMIN_ROOT_PATH . 'include/admin_user_fun.php');
	$add_username = ! empty ( $_POST ['username'] ) ? trim ( $_POST ['username'] ) : showmsg ( '請填寫用戶名！', 1 );
	$add_password = ! empty ( $_POST ['password'] ) ? trim ( $_POST ['password'] ) : showmsg ( '請填寫密碼！', 1 );
	if (strlen ( trim ( $_POST ['username'] ) ) < 3)
	showmsg ( '用戶名必須為3位以上！', 1 );
	if (strlen ( trim ( $_POST ['password'] ) ) < 6)
	showmsg ( '密碼必須為6位以上！', 1 );
	($add_password != trim ( $_POST ['password1'] )) ? showmsg ( '兩次輸入的密碼不相同！', 1 ) : '';
	$add_member_type = ! empty ( $_POST ['member_type'] ) ? trim ( $_POST ['member_type'] ) : showmsg ( '你沒有選擇注冊類型！', 1 );
	$add_email = ! empty ( $_POST ['email'] ) ? trim ( $_POST ['email'] ) : showmsg ( '請填寫電子郵箱！', 1 );
	if (empty ( $add_email ) || ! ereg ( "^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$", $add_email ))
	showmsg ( '電子郵箱格式錯誤！', 1 );
	(! is_numeric ( $add_member_type ) || $add_member_type + 0 == 0) ? showmsg ( '注冊出錯！', 0 ) : '';
	$ck_user = get_company_user ( $add_username );
	$ck_user ? showmsg ( '該用戶名已經被使用！', 1 ) : '';
	$ck_email = get_company_user ( $add_email );
	$ck_email ? showmsg ( '該 Email 已經被注冊！', 1 ) : '';
	if (! $ck_user && ! $ck_email) {
		$pwd_hash = randstr ();
		$password_hash = md5 ( md5 ( $add_password ) . $pwd_hash );
		$sql = "INSERT INTO " . table ( 'members' ) . " (username,password,pwd_hash,email,reg_time,reg_ip) VALUES ('$add_username','$password_hash','$pwd_hash', '$add_email', '$timestamp','$online_ip')";
		$db->query ( $sql );
		$insert_id = $db->insert_id ();
		$sql1 = "INSERT INTO " . table ( 'members_type' ) . " (uid,utype) VALUES ('$insert_id','$add_member_type')";
		$db->query ( $sql1 );
		if ($add_member_type == "1") {
			$sql2 = "INSERT INTO " . table ( 'members_points' ) . " (uid) VALUES ('$insert_id')";
			$db->query ( $sql2 );
			$regpoints_num = intval ( $_POST ['regpoints_num'] );
			if ($_POST ['regpoints'] == "y") {
				$regpoints_num > 0 ? report_deal ( $insert_id, 1, $regpoints_num, '<span style=color:#FF6600>注冊會員系統自動贈送!</span>' ) : '';
			}
		}
	}
	$link [0] ['text'] = "返回列表";
	$link [0] ['href'] = "?act=members_list";
	showmsg ( '添加成功！', 2, $link );
}
//編輯會員
if ($act == 'user_edit') {
	require_once (ADMIN_ROOT_PATH . 'include/admin_user_fun.php');
	$company_user = get_user_inusername ( $_GET ['uname'] );
	$smarty->assign ( 'pageheader', "管理中心 - 企業會員 - 修改" );
	$smarty->assign ( 'company_user', $company_user );
	$smarty->assign ( 'userpoints', get_user_points ( $company_user ['uid'] ) );
	$smarty->assign ( 'url', $_SERVER ["HTTP_REFERER"] );
	$smarty->display ( 'admin_member_company_user_edit.htm' );
}
//增加減少積分
if ($act == 'userpoints_edit') {
	if (intval ( $_POST ['points'] ) < 1 || ! is_numeric ( $_POST ['points'] ))
	showmsg ( '請輸入積分！', 1 );
	if (trim ( $_POST ['points_notes'] ) == '')
	showmsg ( '請填寫積分操作說明！', 1 );
	$link [0] ['text'] = "返回列表";
	$link [0] ['href'] = $_POST ['url'];
	report_deal ( intval ( $_POST ['uid'] ), intval ( $_POST ['points_type'] ), intval ( $_POST ['points'] ), trim ( $_POST ['points_notes'] ) ) ? showmsg ( '操作成功！', 2, $link ) : showmsg ( '操作失敗！', 1 );
}
//修改會員的密碼
if ($act == 'userpass_edit') {
	if (strlen ( trim ( $_POST ['password'] ) ) < 6)
	showmsg ( '新密碼必須為6位以上！', 1 );
	if ($_POST ['password'] != $_POST ['password1'])
	showmsg ( '兩次輸入的密碼不同', 1 );
	require_once (ADMIN_ROOT_PATH . 'include/admin_user_fun.php');
	$user_info = get_user_inusername ( $_POST ['username'] );
	$pwd_hash = $user_info ['pwd_hash'];
	$md5password = md5 ( md5 ( trim ( $_POST ['password'] ) ) . $pwd_hash );
	if ($db->query ( "UPDATE " . table ( 'members' ) . " SET password = '$md5password'  WHERE uid='" . $user_info ['uid'] . "'" )) {
		$link [0] ['text'] = "返回列表";
		$link [0] ['href'] = $_POST ['url'];
		showmsg ( '操作成功！', 2, $link );
	} else {
		showmsg ( '操作失敗！', 1 );
	}
}
//修改會員狀態
if ($act == 'userstatus_edit') {
	if ($db->query ( "UPDATE " . table ( 'members' ) . " SET status = '" . intval ( $_POST ['status'] ) . "'  WHERE uid='" . intval ( $_POST ['userstatus_uid'] ) . "'" )) {
		$link [0] ['text'] = "返回列表";
		$link [0] ['href'] = $_POST ['url'];
		showmsg ( '操作成功！', 2, $link );
	} else {
		showmsg ( '操作失敗！', 1 );
	}
}
//*****************************************用戶區參數設置************************
//企業用戶區參數設置
if ($act == 'set') {
	$smarty->assign ( 'pageheader', "管理中心 - 企業用戶相關設置" );
	$smarty->assign ( 'config', get_cache ( 'config', true ) );
	$smarty->display ( 'admin_member_company_set.htm' );
}
//保存--企業用戶區參數設置
if ($act == 'set_save') {
	foreach ( $_POST as $k => $v ) {
		! $db->query ( "UPDATE " . table ( "config" ) . " SET value='$v' WHERE name='$k'" ) ? showmsg ( '更新設置失敗', 1 ) : "";
	}
	get_cache ( 'config', true );
	showmsg ( "保存成功！", 2 );
}
?>
